<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>IMYOURS | 企业即时通讯软件</title>

<link rel="stylesheet" href="../css/reset.css" type="text/css"
	media="screen" title="no title" />
<link rel="stylesheet" href="../css/text.css" type="text/css"
	media="screen" title="no title" />
<link rel="stylesheet" href="../css/form.css" type="text/css"
	media="screen" title="no title" />
<link rel="stylesheet" href="../css/buttons.css" type="text/css"
	media="screen" title="no title" />
<link rel="stylesheet" href="../css/grid.css" type="text/css"
	media="screen" title="no title" />
<link rel="stylesheet" href="../css/layout.css" type="text/css"
	media="screen" title="no title" />

<link rel="stylesheet"
	href="../css/ui-darkness/jquery-ui-1.8.12.custom.css" type="text/css"
	media="screen" title="no title" />
<link rel="stylesheet" href="../css/plugin/jquery.visualize.css"
	type="text/css" media="screen" title="no title" />
<link rel="stylesheet" href="../css/plugin/facebox.css" type="text/css"
	media="screen" title="no title" />
<link rel="stylesheet" href="../css/plugin/uniform.default.css"
	type="text/css" media="screen" title="no title" />
<link rel="stylesheet" href="../css/plugin/dataTables.css"
	type="text/css" media="screen" title="no title" />

<link rel="stylesheet" href="../css/custom.css" type="text/css"
	media="screen" title="no title">
<style type="text/css">
.accordion_panel {
	height: 50px;
}

.department {
	margin-left: 5px;
	font-size: 18px;
	color: orange;
	display: list-item;
}

.emp {
	color: green;
	margin-left: 4px;
}
</style>
</head>

<body>

	<div id="wrapper">
		<div id="top">

			<div class="content_pad">
				<ul class="right">
					<li><a href="javascript:;" class="top_icon"><span
							class="ui-icon ui-icon-person" id="useruser"></span></a></li>
					<li><a href="javascript:;" class="new_messages top_alert"
						id="unreadMsgTip"></a></li>
					<li><a href="../pages/settings.html">Settings</a></li>
					<li><a href="javascript:parent.logout();">退出登录</a></li>
				</ul>
			</div>
			<!-- .content_pad -->

		</div>
		<!-- #top -->

		<div id="header">

			<div class="content_pad">
				<h1>
					<a href="../index.html">IMYOURS</a>
				</h1>

				<ul id="nav">
					<li class="nav_icon"><a href="../index.html"><span
							class="ui-icon ui-icon-home"></span>消息中心</a></li>

					<li class="nav_icon"><a href="friendList.html"><span
							class="ui-icon ui-icon-gripsmall-diagonal-se"></span>好友列表</a></li>

					<li class="nav_dropdown nav_current nav_icon""><a
						href="companyStruct.html"><span class="ui-icon ui-icon-gear"></span>公司结构</a></li>
					<li class="nav_icon"><a href="admin.html"><span
							class="ui-icon ui-icon-signal"></span>管理页</a></li>


				</ul>
			</div>
			<!-- .content_pad -->

		</div>
		<!-- #header -->

		<div id="masthead">

			<div class="content_pad">

				<h1 class="">部门列表</h1>

				<div id="bread_crumbs">
					<a href="../index.html">消息中心</a> / <a href="javascript:;"
						class="current_page">部门列表</a>
				</div>
				<!-- #bread_crumbs -->

				<div id="search">
					<form action="/search" method="get">
						<input type="text" value="" placeholder="Search" name="search"
							id="search_input" title="Search" /> <input type="submit"
							value="" name="submit" class="submit" />
					</form>
				</div>
				<!-- #search -->

			</div>
			<!-- .content_pad -->

		</div>
		<!-- #masthead -->

		<div id="content" class="xgrid">
			<div class="x9">
				<div id="contentLeft"></div>
			</div>
			<div class="x3" id="panelRight">
				<div class="accordion_container">
					<h2 class="accordion_panel">
						<a href="#">添加好友</a>
					</h2>
					<div class="accordion_content">
						<div>
							<span>好友:</span>
						</div>
						<div>
							<div id="selectedUserNickname" class="usernickname"></div>
						</div>
						<div>
							<span>加入分组</span>
						</div>
						<div>
							<select id="teamSelector"></select>
						</div>
						<div>
							<button class="btn btn-orange">添加好友</button>
							<button onclick="openDialog();" class="btn btn-orange">发起会话</button>
						</div>
					</div>
					<h2 class="accordion_panel">
						<a href="#">添加分组</a>
					</h2>
					<div class="accordion_content">
						<div class="">
							<input type="text" id="teamInput" />
						</div>
						<div>
							<button onclick="addTeam()" class="btn btn-orange">添加分组</button>
						</div>
					</div>
					<h2 class="accordion_panel">
						<a href="#">添加部门</a>
					</h2>
					<div class="accordion_content">
						<div>父部门</div>
						<div id="parentDepartment"></div>
						<div>部门名称</div>
						<div>
							<input type="text" id="departmentNameInput" />
						</div>
						<div>
							<button onclick='insertDepartment();' class="btn btn-orange">添加部门</button>
						</div>
					</div>
				</div>
			</div>
		</div>
		<!-- #content -->

		<div id="footer">
			<div class="content_pad">
				<p>
					&copy; 2010-11 Copyright <a href="http://weibo.com/slevenc">Slevenc</a>.
					Powered by <a href="http://madebyamp.com/themes/dashboard/">Dashboard
						Admin</a>.
				</p>
			</div>
			<!-- .content_pad -->
		</div>
		<!-- #footer -->

	</div>
	<!-- #wrapper -->

	<script src="../js/jquery/jquery-1.5.2.min.js"></script>
	<script src="../js/jquery/jquery-ui-1.8.12.custom.min.js"></script>
	<script src="../js/misc/excanvas.min.js"></script>
	<script src="../js/jquery/facebox.js"></script>
	<script src="../js/jquery/jquery.visualize.js"></script>
	<script src="../js/jquery/jquery.dataTables.min.js"></script>
	<script src="../js/jquery/jquery.tablesorter.min.js"></script>
	<script src="../js/jquery/jquery.uniform.min.js"></script>
	<script src="../js/jquery/jquery.placeholder.min.js"></script>
	<script src="../js/init.js"></script>
	<script src="../js/json2.js"></script>
	<script src="../js/var.js"></script>


	<script src="../js/widgets.js"></script>
	<script src="../js/dashboard.js"></script>

	<script>
		$(document).ready(
				function() {
					getDepartment();
					reload();
					vlidateSid();
					Dashboard.init();
					setTimeout('getUnreadMsgCount()', 1000);

					$("#useruser").after(parent.userInfo.user.nickname);
					$('.accordion_container').accordion();

					$('.tab_container').tabs();

					$('#datepicker').datepicker();

					$("#progressbar").progressbar({
						value : 59
					});

					$('#slider-range').slider(
							{
								range : true,
								min : 0,
								max : 500,
								values : [ 75, 300 ],
								slide : function(event, ui) {
									$("#amount").val(
											"$" + ui.values[0] + " - $"
													+ ui.values[1]);
								}
							});

					$("#amount").val(
							"$" + $("#slider-range").slider("values", 0)
									+ " - $"
									+ $("#slider-range").slider("values", 1));

				});

		function reload(data) {
			if (data == null) {
				data = parent.getFriendList(reload);
			} else {
				$("#teamSelector").empty();
				$.each(data.teams, function(k, v) {
					$("#teamSelector").append(
							$("<option value="+v.id+" >" + v.name
									+ "</option >"));
				});
			}
		}

		function getUnreadMsgCount() {
			count = parent.unReadMsgBox.length;
			if (count == 0) {
				$("#unreadMsgTip").text('没有未读的消息');
			} else {
				$("#unreadMsgTip").text('您有' + count + '条新消息');
			}
			setTimeout('getUnreadMsgCount()', 1000);
		}

		function getDepartment() {
			$.post('../' + getUrl(), {
				service : 'getDepartment',
				sessionId : parent.sid
			}, function(data) {
				jo = JSON.parse(data);
				if (jo.state == 'success') {
					$('#contentLeft').empty();
					$('#contentLeft').append(genDiv(jo.data));
				} else {
					parent.errorDisposer(jo.error);
				}
			})
		}

		function genDiv(data) {
			var divname = $("<div class='department_name'></div>");
			divname.text(data.name);
			var divemp = $("<div class='divemp'></div>");
			$.each(data.users, function(k, v) {
				emp = $('<div class="emp"></div>');
				emp.text(v.nickName);
				emp.click(function() {
					selectedUser = v;
					reflash();
				});
				divemp.append(emp);
			});
			var divchild = $('<div class="divchild"></div>');
			$.each(data.child, function(k, v) {
				divchild.append(genDiv(v));
			});
			divemp.hide();
			divchild.hide();
			divname.click(function() {
				divemp.toggle();
				divchild.toggle();
				selectedDepartment = data;
				reflash();
			});
			var d = $("<div class='department'></div>");
			d.append(divname);
			d.append(divemp);
			d.append(divchild);
			return d;
		}

		function reflash() {
			if (selectedUser != null) {
				$("#selectedUserNickname").text(selectedUser.nickName);
			}
			if (selectedDepartment != null) {
				$("#parentDepartment").text(selectedDepartment.name);
			}
		}

		var selectedDepartment = null;
		var selectedUser = null;

		//响应插入部门方法		
		function insertDepartment() {
			if (selectedDepartment != null) {
			}
			$.post('../' + getUrl(), {
				service : 'insertDepartment',
				sessionId : parent.sid,
				parentDepartment : selectedDepartment.id,
				name : $("#departmentNameInput").val()
			}, function(data) {
				var jo = JSON.parse(data);
				if (jo.state == 'success') {
					getDepartment();
				} else {
					parent.errorDisposer(data.error);
				}
			});
		}
		function openDialog() {
			if (selectedUser != null) {
				parent.openDialog(selectedUser.id, selectedUser.nickName, null);
			}

		}
		function addFriend() {
			if(selectedUser!=null){
				$.post('../'+getUrl(),{
					service:'addFriend',
					sessionId:parent.sid,
					userId:selectedUser.id,
					teamId:$("#teamSelector").val()
				},function(data){
					var jo = JSON.parse(data);
					if(jo.state == 'success'){
						alert("添加成功");
					}else{
						parent.errorDisposer(jo.error);
					}
					
				});
			}
		}
	</script>

</body>

</html>